package dailyTemperatures;

import java.util.Stack;

public class Solution {
    // 单调栈
    public int[] dailyTemperatures(int[] temperatures) {
        int[]answer = new int[temperatures.length];
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < temperatures.length; i++) {
            while (!stack.isEmpty()&&stack.peek()<temperatures[i]){
                answer[stack.peek()] = i-stack.pop(); // 单调栈里面存放的是之前遍历过的元素，递增形式
            }
            stack.push(i);
        }
        return answer;
    }
}
